package me.chan.prime;

import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;
import static java.util.stream.Collectors.*;

public class PrimeDemo {

	public static void main(String[] args) {
		//分区判断给定的前n个数中的质数和非质数
		Map<Boolean, List<Integer>> partitionedIntegerByIsPrime = 
				IntStream.rangeClosed(2, 100).boxed().collect(
					partitioningBy(PrimeDemo::isPrime));
		
		System.out.println(partitionedIntegerByIsPrime);
				
	}
	
	public static boolean isPrime(int cadidate) {
		int cadidateRoot = (int)Math.sqrt((double)cadidate);
		return IntStream.rangeClosed(2, cadidateRoot).noneMatch(
					n -> cadidate % n == 0
				);
	}

}
